import asyncio
import time
import os


async def process_file(file_path):
    print('开始请求url',file_path) 
    await asyncio.sleep(2)
    with open(file_path,'r',encoding='utf-8') as file:
        content = file.readlines()
        vaild_lines = [line for line in content if "error" in line]
    print(f"处理{file_path}完成，共{len(vaild_lines)}条错误")

async def main():
    file_paths = ['log1.txt','log2.txt','log3.txt'] 
    for path in file_paths:
        if not os.path.exists(path):
            with open(path,'w',encoding='utf-8') as file:
                file.write('ERROR:Something went wrong')

    tasks = [asyncio.create_task(process_file(path))for path in file_paths]
    results = await asyncio.wait(tasks)
    results = [task.result() for task in results[0]]



    

if __name__ == '__main__':
    asyncio.run(main())









       


